package com.glory.huaweipda.viewmodel

import com.afollestad.materialdialogs.MaterialDialog
import com.glory.huaweipda.model.TaskRepository
import com.glory.mvvmnet.base.BaseViewModel
import com.glory.mvvmnet.entity.CallObserveBean
import com.google.gson.JsonObject

class SkipDialogModel : BaseViewModel(){


    private val repository by lazy { TaskRepository() }
    lateinit var dialog:MaterialDialog

    fun defaultLotInfo(eqpID: String, user: String, lotID: String) {
        val map = JsonObject()
        map.addProperty("Lotid", lotID)
        map.addProperty("Eqpid", eqpID)
        map.addProperty("Opid", user)
        map.addProperty("TrackStatus", "")
        map.addProperty("IsUploadSpc", "0")
        launchWithError({
            val defaultLotInfo =
                repository.defaultLotInfo(map)
            val lotInfo = defaultLotInfo.lots[0]
            when(lotInfo.trackStatus){
                "TRACKIN" ->{
                    defUI.callObserve.value = CallObserveBean(0,defaultLotInfo)
                }
                "TRACKOUT" ->{
                    defUI.callObserve.value = CallObserveBean(1,defaultLotInfo)
                }
            }

        },{
            defUI.callObserve.value = CallObserveBean(2)
        },true)
    }
    fun defaultEqpStateChangeInfo(eqpID: String,isState:Boolean) {
        val map = JsonObject()
        map.addProperty("eqpid", eqpID)
        map.addProperty("eqpstate", if (isState){"loca"}else{"remote"})
        launchOnlyResult({
            repository.defaultEqpStateChangeInfo(map)
        },true)
    }
}